﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace KCurveAPI
{
  public class CodeManager : ConfigurationSection
  {
    [ConfigurationProperty("filter", DefaultValue = @".\", IsRequired = true)]
    public string filter
    {
      get { return (string)this["filter"]; }
      set { this["filter"] = value; }
    }

    [ConfigurationProperty("", IsDefaultCollection = true)]
    public TableInfoCollection TableInfos
    {
      get
      {
        return (TableInfoCollection)base[""];
      }
    }
  }


  public class TableInfoCollection : ConfigurationElementCollection
  {
    protected override ConfigurationElement CreateNewElement()
    {
      return new Code();
    }
    protected override object GetElementKey(ConfigurationElement element)
    {
      return ((Code)element).name;
    }

    public override ConfigurationElementCollectionType CollectionType
    {
      get
      {
        return ConfigurationElementCollectionType.BasicMap;
      }
    }
    protected override string ElementName
    {
      get
      {
        return "Code";
      }
    }

    public Code this[int index]
    {
      get
      {
        return (Code)BaseGet(index);
      }
      set
      {
        if (BaseGet(index) != null)
        {
          BaseRemoveAt(index);
        }
        BaseAdd(index, value);
      }
    }
  }
}
